import { defineComponent } from 'vue';
import AMapLoader from '@amap/amap-jsapi-loader';
export default defineComponent({
  data() {
    return {
      path: [],
      current_position: [],
      map: null as any,
      mapModule: null as any,
    };
  },
  mounted() {
    setTimeout(() => {
      this.loadMapScript();
    });
  },
  methods: {
    loadMapScript() {
      console.log(this.map);

      if (!!this.map) {
        this.map.destroy();
      }
      AMapLoader.load({
        key: '16bdc2d566859fa6c5ac3ad0b45a0932', // 申请好的Web端开发者Key，首次调用 load 时必填
        version: '2.0', // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
      })
        .then((AMap) => {
          this.mapModule = AMap;
          this.map = new AMap.Map('gd_map_d');
          console.log(this.map);
        })
        .catch((e) => {
          console.log(e);
        });
    },
  },
  destroyed() {
    this.map.destroy();
    this.map = null;
  },
});
